//
//  FMPersonHeaderView.m
//  PsychologyFM
//
//  Created by zhang on 16/1/22.
//  Copyright © 2016年 ZhangLuDu. All rights reserved.
//

#import <UIImageView+WebCache.h>
#import "FMPersonHeaderView.h"

@implementation FMPersonHeaderView

- (instancetype)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (self) {
        [self addSubview];
    }
    return self;
}
- (void)addSubview{
    //  顶部背景图
    _topBGImgView = [[UIImageView alloc]initWithFrame:(CGRectMake(0, 0, kScreenWidth, kScreenHeight / 5))];
    _topBGImgView.image = [UIImage imageNamed:@"bg1"];
    [self addSubview:_topBGImgView];
    
    //  头标Label
    _iconImgView = [[UIImageView alloc]initWithFrame:CGRectMake(10, _topBGImgView.bottom - 15, 70, 70)];
    _iconImgView.image = [UIImage imageNamed:@"fm50"];
    _iconImgView.layer.masksToBounds = YES;
    _iconImgView.layer.cornerRadius = 35;
    [self addSubview:_iconImgView];
    
    //  nickLabel
    _nickNameIConLabel = [[UILabel alloc]initWithFrame:CGRectMake(_iconImgView.right + 5, _iconImgView.top + 22.5, 200, 30)];
    _nickNameIConLabel.text = @"ssssssssssss";
    _nickNameIConLabel.textAlignment = NSTextAlignmentLeft;
    [self addSubview:_nickNameIConLabel];
    
    //  introduceLabel
    _introduceLabel = [[UILabel alloc]initWithFrame:CGRectMake(_nickNameIConLabel.left, _nickNameIConLabel.bottom + 5, kScreenWidth - 100, 20)];
//    _introduceLabel.text = @"hashdjahfkashfjklashfkjahsfkalhkfashklfhsadas";
    self.introduceLabel.font = [UIFont systemFontOfSize:12];
    self.introduceLabel.textColor = [UIColor colorWithRed:155/255.0 green:155/255.0 blue:155/255.0 alpha:1];
    [self addSubview:_introduceLabel];
    UIView *view = [[UIView alloc]initWithFrame:CGRectMake(kMartin10, self.introduceLabel.bottom + kMartin20, kScreenWidth - kMartin20, 1)];
    view.backgroundColor = FMGray;
    [self addSubview:view];
    
    self.collectionCountLable = [[UILabel alloc]initWithFrame:CGRectMake(kMartin10, view.bottom + kMartin10, kScreenWidth - kMartin20, kMartin25)];
    
    [self addSubview:self.collectionCountLable];
    
    UIView *bottomLine = [[UIView alloc]initWithFrame:CGRectMake(kMartin10, self.collectionCountLable.bottom + kMartin5, kScreenWidth - kMartin20, 1)];
    bottomLine.backgroundColor = FMOrange;
    [self addSubview:bottomLine];
    
}

- (void)setModel:(FMPersonModel *)model{

    _model = model;
    
    [self.iconImgView sd_setImageWithURL:[NSURL URLWithString:model.avatar] placeholderImage:nil];
    
    self.nickNameIConLabel.text = model.nickname;
    
    if (model.introduce == nil || model.introduce.length == 0) {
        self.introduceLabel.text = @"Ta还没有写简介呢";
    } else {
        self.introduceLabel.text = model.introduce;
    }
    self.collectionCountLable.text = @"Ta的收藏";
    self.collectionCountLable.textColor = FMOrange;
    


}

@end
